package htmodels

import (
	"github.com/astaxie/beego/orm"
	"choujiang/models"
)
func HTPositionAdd(position *models.Position) error {
	o := orm.NewOrm()
	_, err := o.Insert(position)
	return err
}

func HTPositionGetDetail(position *models.Position) error {
	o := orm.NewOrm()
	return o.Read(position)
}

func HTPositionGetCount(search string, searchFiled string ) (int64, error) {
	o := orm.NewOrm()
	m := models.Position{}
	count, err := o.QueryTable(m.TableName()).Filter(searchFiled + "__icontains", search).Count()
	return count, err
}

func HTPositionGetList(positions *[]models.Position, fields []string , offset int64, limit int, search string, searchFiled string, orderby string) error {
	o := orm.NewOrm()
	m := models.Position{}
	_, err := o.QueryTable(m.TableName()).Filter(searchFiled + "__icontains", search).OrderBy(orderby).Offset(offset).Limit(limit).All(positions, fields...)
	return err
}

func HTPositionDelete(Ids []int64) (int64, error) {
	o := orm.NewOrm()
	m := models.Position{}
	count, err := o.QueryTable(m.TableName()).Filter("Id" + "__in", Ids).Delete()
	return count, err
}
func HTPositionUpdate(position *models.Position) error {
	o := orm.NewOrm()
	_, err := o.Update(position)
	return err
}